//-----------------------------------------------------------------------
//<copyright file="BienBanKiemKeKhoDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class BienBanKiemKeKhoDAO : SQLDatabase, IBienBanKiemKeKhoDAO
	{

		#region Create BienBanKiemKeKho methods

		public BienBanKiemKeKho CreateBienBanKiemKeKho(BienBanKiemKeKho bienBanKiemKeKho)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoInsert");
				AddOutParameter(command, "@MaBBKKK", SqlDbType.NVarChar, bienBanKiemKeKho.MaBBKKK);
				AddInParameter(command, "@Thang", SqlDbType.TinyInt, bienBanKiemKeKho.Thang);
				AddInParameter(command, "@Nam", SqlDbType.Int, bienBanKiemKeKho.Nam);
				AddInParameter(command, "@NgayThucHien", SqlDbType.DateTime, bienBanKiemKeKho.NgayThucHien);
				AddInParameter(command, "@NguoiThucHien", SqlDbType.NVarChar, bienBanKiemKeKho.NguoiThucHien);
				AddInParameter(command, "@ThuKho", SqlDbType.NVarChar, bienBanKiemKeKho.ThuKho);
				AddInParameter(command, "@KeToan", SqlDbType.NVarChar, bienBanKiemKeKho.KeToan);
				AddInParameter(command, "@GiamDoc", SqlDbType.NVarChar, bienBanKiemKeKho.GiamDoc);
				AddInParameter(command, "@KetLuan", SqlDbType.TinyInt, bienBanKiemKeKho.KetLuan);
				AddInParameter(command, "@NguyenNhan", SqlDbType.NVarChar, bienBanKiemKeKho.NguyenNhan);
				AddInParameter(command, "@YKien", SqlDbType.NVarChar, bienBanKiemKeKho.YKien);
                AddInParameter(command, "@MaKy", SqlDbType.NVarChar, bienBanKiemKeKho.MaKy);

				ExecuteNonQuery(command);
                bienBanKiemKeKho.MaBBKKK = (string)GetParameterValue(command, "@MaBBKKK");
				return bienBanKiemKeKho;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateBienBanKiemKeKhoException", ex);
			}
		}

		#endregion

		#region Update BienBanKiemKeKho methods

		public void UpdateBienBanKiemKeKho(BienBanKiemKeKho bienBanKiemKeKho)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoUpdate");

				AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, bienBanKiemKeKho.MaBBKKK);
				AddInParameter(command, "@Thang", SqlDbType.TinyInt, bienBanKiemKeKho.Thang);
				AddInParameter(command, "@Nam", SqlDbType.Int, bienBanKiemKeKho.Nam);
				AddInParameter(command, "@NgayThucHien", SqlDbType.DateTime, bienBanKiemKeKho.NgayThucHien);
				AddInParameter(command, "@NguoiThucHien", SqlDbType.NVarChar, bienBanKiemKeKho.NguoiThucHien);
				AddInParameter(command, "@ThuKho", SqlDbType.NVarChar, bienBanKiemKeKho.ThuKho);
				AddInParameter(command, "@KeToan", SqlDbType.NVarChar, bienBanKiemKeKho.KeToan);
				AddInParameter(command, "@GiamDoc", SqlDbType.NVarChar, bienBanKiemKeKho.GiamDoc);
				AddInParameter(command, "@KetLuan", SqlDbType.TinyInt, bienBanKiemKeKho.KetLuan);
				AddInParameter(command, "@NguyenNhan", SqlDbType.NVarChar, bienBanKiemKeKho.NguyenNhan);
				AddInParameter(command, "@YKien", SqlDbType.NVarChar, bienBanKiemKeKho.YKien);
                AddInParameter(command, "@MaKy", SqlDbType.NVarChar, bienBanKiemKeKho.MaKy);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateBienBanKiemKeKhoException", ex);
			}
		}

		#endregion

		#region Delete BienBanKiemKeKho methods

		public void DeleteBienBanKiemKeKho(BienBanKiemKeKho bienBanKiemKeKho)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoDelete");

				AddInParameter(command, "@MaBBKKK", SqlDbType.NVarChar, bienBanKiemKeKho.MaBBKKK);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteBienBanKiemKeKhoException", ex);
			}
		}

		#endregion

		#region Select methods

		#region GetAll BienBanKiemKeKho methods

		public BienBanKiemKeKhos GetAllBienBanKiemKeKho()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoGetList");
				BienBanKiemKeKhos Result = new BienBanKiemKeKhos();
				List<BienBanKiemKeKho> List = ExecuteQuery<BienBanKiemKeKho>(command,true);
				foreach(BienBanKiemKeKho item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllBienBanKiemKeKhoException", ex);
			}
		}

		#endregion


		#region GetBienBanKiemKeKho methods

		public BienBanKiemKeKho GetBienBanKiemKeKhoByID(string maBBKKK)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spBienBanKiemKeKhoGet");

				AddInParameter(command, "@maBBKKK", SqlDbType.NVarChar, maBBKKK);

				return ExecuteQuery<BienBanKiemKeKho>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetBienBanKiemKeKhoBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
